package top.datacluster.basic.algorithm.leetcode.tree;

import top.datacluster.basic.algorithm.leetcode.TreeNode;

public class LeetCode1565 {

    public boolean isSymmetric(TreeNode root) {
        if (root == null){
            return true;
        }else{
            return judge(root.left, root.right);
        }
    }

    public boolean judge(TreeNode left, TreeNode right){
        if (left == null && right == null){
            return true;
        }
        if (left == null || right == null){
            return false;
        }
        if (left.val == right.val){
            if (judge(left.left, right.right)){
                return judge(left.right, right.left);
            }else{
                return false;
            }

        }else{
            return false;
        }

    }


}
